<?php

namespace addons\mall\controller;

use think\Cookie;
use think\Hook;
use think\Config;
use think\Validate;
use think\Session;
use think\Db;

class Index extends Base
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function _initialize()
    {
        parent::_initialize();

        $auth = $this->auth;
        
        if (!Config::get('fastadmin.usercenter')) {
            $this->error(__('User center already closed'));
        }
        
        $ucenter = get_addon_info('ucenter');
        if ($ucenter && $ucenter['state']) {
            include ADDON_PATH . 'ucenter' . DS . 'uc.php';
        }
    }

    public function index()
    {
        //插件安装提示
        $addonsTip = [];
        $user = get_addon_info('user');
        if(!$user) $addonsTip[] = "请先在后台安装配置<a href=\"https://www.fastadmin.net/store/user.html\" target=\"_blank\">[用户扩展]</a>插件！";
        elseif(!$user['state']) $addonsTip[] = "请在插件管理中启用<a href=\"https://www.fastadmin.net/store/user.html\" target=\"_blank\">[用户扩展]</a>插件！";
        $exist = \think\Db::query("show tables like'".config('database.prefix')."area'");
        if(!$exist) $addonsTip[] = "地区数据不存在，请安装<a href=\"https://www.fastadmin.net/store/example.html\" target=\"_blank\">[开发示例]</a>插件！";
        $epay = get_addon_info('epay');
        if(!$epay) $addonsTip[] = "请在后台安装配置<a href=\"https://www.fastadmin.net/store/epay.html\" target=\"_blank\">[微信支付宝整合]</a>插件！";
        elseif(!$epay['state']) $addonsTip[] = "请在插件管理中启用<a href=\"https://www.fastadmin.net/store/epay.html\" target=\"_blank\">[微信支付宝整合]</a>插件！";
        $recharge = get_addon_info('recharge');
        if(!$recharge) $addonsTip[] = "请在后台安装配置<a href=\"https://www.fastadmin.net/store/recharge.html\" target=\"_blank\">[会员充值余额]</a>插件！";
        elseif(!$recharge['state']) $addonsTip[] = "请在插件管理中启用<a href=\"https://www.fastadmin.net/store/recharge.html\" target=\"_blank\">[会员充值余额]</a>插件！";
        $editable = get_addon_info('editable');
        if(!$editable) $addonsTip[] = "请在后台安装配置<a href=\"https://www.fastadmin.net/store/editable.html\" target=\"_blank\">[表格无刷新行内编辑]</a>插件！";
        elseif(!$editable['state']) $addonsTip[] = "请在插件管理中启用<a href=\"https://www.fastadmin.net/store/editable.html\" target=\"_blank\">[表格无刷新行内编辑]</a>插件！";
        $vbot = get_addon_info('vbot');
        if(!$vbot) $addonsTip[] = "请在后台安装配置<a href=\"https://www.fastadmin.net/store/vbot.html\" target=\"_blank\">[企业微信通知机器人]</a>插件！";
        elseif(!$vbot['state']) $addonsTip[] = "请在插件管理中启用<a href=\"https://www.fastadmin.net/store/vbot.html\" target=\"_blank\">[企业微信通知机器人]</a>插件！";
        $this->assign('addonsTip',$addonsTip);

        if($this->request->url()=='/index')  $this->redirect(addon_url('mall/index/index'));
        $model = new \app\common\model\mall\goods\Cat();
        $categorys = $model->getFloors();
        $this->assign('floors',$categorys);
        $this->assign('hideCategory',1);
        
        //获取用户积分
        $this->assign('object',$this->auth->score);
        // 店铺街数据
        $shopStreet = model('Shop','common\model\mall\shop')->indexShopQuery();
        $this->assign('shopStreet',$shopStreet);
        $url = $this->request->url();
        $nav=\app\common\model\mall\oper\Nav::where("navUrl",$url)->select();
        $this->view->assign("__NAV__", $nav);
        return $this->fetch();
    }

    public function news()
    {
        $newslist = [];
        return jsonp(['newslist' => $newslist, 'new' => count($newslist), 'url' => 'http://www.fast.mobi?ref=news']);
    }

    /**
     * 跳到用户注册协议
     */
    public function protocol(){
        return $this->fetch("user_protocol");
    }

}
